<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath() + "/";
	//response.sendRedirect("common/login");
%>
<c:set var="path" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TaskJobList</title>
<script type="text/javascript"
	src="${path }/resource/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="${path }/resource/js/mytools.js"></script>
<script type="text/javascript" src="${path }/resource/layer/layer.js"></script>
	<script type="text/javascript" src="${path }/resource/layui/layui.js" ></script>
	<link rel="stylesheet" href="${path }/resource/layui/css/layui.css" />
	
</head>
<body>

	<input type="hidden" id="rowIndex">
	
<form class="layui-form layui-form-pane" action="" id="from1">
<input type="hidden" name="id" value="${obj.id}"/> <!--隐藏域id el表达式获取 -->
<div class="layui-form-item">
	<div class="layui-inline">
      <label class="layui-form-label">jobName</label>
      <div class="layui-input-inline">
      	<input type="text" name="jobName" class="layui-input" placeholder="jobName" value="${obj.jobName}" id="jobName"/>
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">gropName</label>
      <div class="layui-input-inline">
      <input type="text" name="gropName" class="layui-input" value="${obj.gropName}" id="gropName"/>
      </div>
    </div>
     <div class="layui-inline">
      <label class="layui-form-label">triggerName</label>
      <div class="layui-input-inline">
      <input type="text" name="triggerName" class="layui-input" value="${obj.triggerName}" id="gropName"/>
      </div>
    </div>
     <div class="layui-inline">
      <label class="layui-form-label">cron</label>
      <div class="layui-input-inline">
      <input type="text" name="cron" class="layui-input" value="${obj.cron}" id="gropName"/>
      </div>
    </div>
</div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <input  type="button" value="查询"  class="layui-btn layui-btn-small"  lay-submit="" lay-filter="form1" onclick=" mjs.search()">
      <input type="reset" class="layui-btn layui-btn-primary layui-btn-small" value="重置">
       <input type="button" value="新增" onclick="mjs.editFrom()" class="layui-btn layui-btn-small"/>
    </div>
  </div>
    <div class="layui-form-item" >
    
     <!--  <input type="button" value="批量删除" onclick="" class="layui-btn layui-btn-danger layui-btn-small"/> -->
      </div>
</form>
	
	<div id="tablediv">
		<table id="table1" class="layui-table">
			<thead id="thead">
				<tr>
					<!-- <th data-name="id" data-format="check">id</th> -->
					<th data-name="id" data-format="operation" style="width:80px;">操作</th>
					<th data-name="jobName">jobName</th>
					<th data-name="gropName">gropName</th>
					<th data-name="triggerName">triggerName</th>
					<th data-name="cron">cron</th>
					<th data-name="status" data-format="operationStatus" style="width:50px;">状态</th>
				</tr>
			</thead>
		</table>
	</div>
	<br>
	<script type="text/javascript">
	$.fn.getHexBackgroundColor = function() {
	    var rgb = $(this).css('background-color');
	        rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
	        function hex(x) {
	            return ("0" + parseInt(x).toString(16)).slice(-2);
	        }
	        rgb = "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
	    return rgb;
	}
	
	
		var mjs = mytooljs.initTable({
			idSelecter : "#table1",
			sendurl : "${path}/user/crawl/TaskJob/showList", //求数据的地址
			pagesize : 5,//分页大小
			delUrl : "${path}/user/crawl/TaskJob/del",//删除数据地址
			editUrl : "${path}/user/crawl/TaskJob/editForm" //打开编辑或新增页面地址
			/*afterload :function(){
				 $("tbody tr").click(function(){
						$("#order").empty();
						$("#rowIndex").val(this.rowIndex);
						var html="";
					 	var table = document.getElementById("table1");
						var tr = table.getElementsByTagName("tr")[$("#rowIndex").val()];
						var	HEX = $(tr).getHexBackgroundColor();
						$(tr).css('background-color','#F0F0F0').siblings().css('background-color','#F8F8F8');
						var td = tr.getElementsByTagName("td");
						var status = td[5].innerHTML;
						var id = td[0].innerHTML;
						id =id.substr(id.indexOf("(")+1,1);
						id=parseInt(id.replace(/[^0-9]/ig,""));
						var param ={
								"id":id,"jobName":td[1].innerHTML,"gropName":td[2].innerHTML,
								"triggerName":td[3].innerHTML,"cron":td[4].innerHTML,"status":td[5].innerHTML
								};
						var param1=JSON.stringify(param);//转成json字符串才能拼接
						if(param.status==0){
							html += "<input type='button' value='启动' class='btn btn-success btn-sm ' onclick='jobOrder("+param1+");'/>";
						}else{
							html += "<input type='button' value='停止' class='btn btn-danger btn-sm ' onclick='jobOrder("+param1+");'/>";
						}
					 	$("#order").append(html);
				});
			} */
		});
				
		//获取表格当前一行的数据
		function operationStatus(status,index){
			var html="";
			var param=JSON.stringify({'index':index,'status':status});
			if(status==0){
				html += "<input type='button' value='启动' class='layui-btn layui-btn-small' onclick='jobOrder("+param+");'/>";
			}else{
				html += "<input type='button' value='停止' class='layui-btn layui-btn-small layui-btn-danger' onclick='jobOrder("+param+");'/>";
			}
			return html;
		}
		//操作	
	 	function operation(id,index) {
			var html = "<div class='layui-btn-group'>";
			html+=
				 " <button class='layui-btn layui-btn-small layui-btn-primary' onclick='mjs.editFrom("+ id + ")' >"
				+" <i class='layui-icon'>&#xe642;</i>"
				+" </button>";
			html+= 
				 " <button class='layui-btn layui-btn-small layui-btn-primary' onclick='mjs.delRec("+ id + ")' >"
				+" <i class='layui-icon'>&#xe640;</i>"
				+" </button>"
			    +"</div>";
			return html;
		} 
		//拿到id和状态发送请求
		function jobOrder(param) {
			var id = document.getElementById("table1").rows[param.index+1].cells[0].innerHTML;
			id = id.substr(id.indexOf("(")+1,1);
			id = parseInt(id.replace(/[^0-9]/ig,""));
			console.log(id);
			param= {'id':id,'status':param.status};
			//发送请求启动或停止
			 if(param.status==0){//启动
				url="${path}/user/crawl/TaskJob/startJob";
			}else{ //停止
				url="${path}/user/crawl/TaskJob/stopJob";
			}
			  $.ajax({
		  		'type':'post',
		  		'url':url,
		  		'data':param,
		  		'dataType':'json',
		  		'success':function(data,status){
		  			/* var page = window.parent.document.getElementById("cpagefont").innerHTML;
		  			page = 	parseInt(page.replace(/[^0-9]/ig,""));
		  			var data = {"currpage":page}; */
		  			//刷新当前页
		  			mjs.refCurr();
		  		},'error':function(){
		  			alert("出错了啊");
		  		}
		  	});  
		}
		layui.use(['layer','form'], function(){
			  var layer = layui.layer;
			  var form = layui.form;
			});
	</script>
</body>
</html>
